// io.cpp
//
// Image I/O

#include "delegates/io.h"

#include <sstream>

namespace simple{
    //
    // ImageIOBase
    //
    // Base class for all apImage storage delegates.

    ImageIOBase::ImageIOBase ()   {}
    ImageIOBase::~ImageIOBase ()  {}

    DelegateParams ImageIOBase::sNoParams;


    //
    // ImageIODelegateList
    //
    ImageIODelegateList* ImageIODelegateList::_sOnly = 0;

    ImageIODelegateList& ImageIODelegateList::gOnly ()
    {
        if (!_sOnly) _sOnly = new ImageIODelegateList ();
        return *_sOnly;
    }

    ImageIODelegateList::ImageIODelegateList () {}


    ImageIOBase* ImageIODelegateList::getDelegate (const std::string& type)
    {
        return _map[type];
    }

    void ImageIODelegateList::setDelegate (const std::string& type, ImageIOBase* object)
    {
        _map[type] = object;
    }

    ImageIOBase* ImageIODelegateList::findDelegate (const std::string& filename)
    {
        iterator i;
        for (i=_map.begin(); i!=_map.end(); i++) {
            if (i->second->info(filename).isDelegate)
                return i->second;
        }

        return 0;
    }

}